package cn.com.niit.product.service.impl;

import cn.com.niit.product.dao.ProductDao;
import cn.com.niit.product.entity.Product;
import cn.com.niit.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductDao productDao;

    @Override
    public Product findById(Long id) {
        Product product = null;
        Optional<Product> byId = productDao.findById(id);
        if (byId.isPresent()) {
            product = byId.get();
        }
        return product;
    }

    @Override
    public void save(Product product) {
        productDao.save(product);
    }

    @Override
    public void update(Product product) {
        productDao.save(product);
    }

    @Override
    public void delete(Long id) {
        productDao.deleteById(id);
    }

}
